#ifndef __WIZ_BASE_TYPE_TIME_HPP__SHANHAOBO_19800429__
#define __WIZ_BASE_TYPE_TIME_HPP__SHANHAOBO_19800429__

#include <time.h>

#include "./WizBaseTypeString.hpp"

namespace Wiz
{
    namespace Time
    {
#if _USE_32BIT_TIME_T
        typedef __time32_t      Type;
#else
        typedef __time64_t      Type;
#endif
        WIZ_DECLARE(::Wiz::Time::Type);

        WIZ_INLINE ::Wiz::Time::RefConst Get(::Wiz::Time::Out OutTM)
        {
            ::time(&OutTM);
            return OutTM;
        }

        WIZ_INLINE ::Wiz::Time::Type Get()
        {
            ::Wiz::Time::Type TM;
            return ::Wiz::Time::Get(TM);
        }
    } /// end of namespace Time

    namespace LocalTime
    {
        typedef tm          Type;
        WIZ_DECLARE(::Wiz::LocalTime::Type);
        
        WIZ_INLINE ::Wiz::Bool::Type Get(::Wiz::LocalTime::Out OutTime, ::Wiz::Time::In InTime)
        {
            return ::localtime_s(&OutTime, &InTime) == 0;
        }

        WIZ_INLINE ::Wiz::Bool::Type Get(::Wiz::LocalTime::Out OutTime)
        {
            ::Wiz::Time::Type TM;
            return ::Wiz::LocalTime::Get(OutTime, ::Wiz::Time::Get(TM));
        }

        WIZ_INLINE ::Wiz::Void::Type ToFormatStr(::Wiz::String::Out OutStr, ::Wiz::String::In InFmt, ::Wiz::LocalTime::In InTime)
        {
            OutStr.Resize(InFmt.Size() + 256);
            OutStr.Resize(::strftime(OutStr.GetBuffer(), OutStr.Size(), InFmt.GetCStr(), &InTime));
        }

        WIZ_INLINE ::Wiz::Void::Type ToFormatStr(::Wiz::WString::Out OutStr, ::Wiz::WString::In InFmt, ::Wiz::LocalTime::In InTime)
        {
            OutStr.Resize(InFmt.Size() + 256);
            OutStr.Resize(::wcsftime(OutStr.GetBuffer(), OutStr.Size(), InFmt.GetCStr(), &InTime));
        }

        WIZ_INLINE ::Wiz::Bool::Type ToFormatStr(::Wiz::String::Out OutStr, ::Wiz::String::In InFmt, ::Wiz::Time::In InTime)
        {
            ::Wiz::LocalTime::Type TempTM;
            if (::Wiz::LocalTime::Get(TempTM, InTime))
            {
                ::Wiz::LocalTime::ToFormatStr(OutStr, InFmt, TempTM);

                return ::Wiz::Bool::True;
            }

            return ::Wiz::Bool::False;
        }

        WIZ_INLINE ::Wiz::Bool::Type ToFormatStr(::Wiz::WString::Out OutStr, ::Wiz::WString::In InFmt, ::Wiz::Time::In InTime)
        {
            ::Wiz::LocalTime::Type TempTM;
            if (::Wiz::LocalTime::Get(TempTM, InTime))
            {
                ::Wiz::LocalTime::ToFormatStr(OutStr, InFmt, TempTM);

                return ::Wiz::Bool::True;
            }

            return ::Wiz::Bool::False;
        }

        WIZ_INLINE ::Wiz::Bool::Type ToFormatStr(::Wiz::String::Out OutStr, ::Wiz::String::In InFmt)
        {
            ::Wiz::LocalTime::Type TempTime;
            if (::Wiz::LocalTime::Get(TempTime))
            {
                ::Wiz::LocalTime::ToFormatStr(OutStr, InFmt, TempTime);

                return ::Wiz::Bool::True;
            }

            return ::Wiz::Bool::False;
        }

        WIZ_INLINE ::Wiz::Bool::Type ToFormatStr(::Wiz::WString::Out OutStr, ::Wiz::WString::In InFmt)
        {
            ::Wiz::LocalTime::Type TempTime;
            if (::Wiz::LocalTime::Get(TempTime))
            {
                ::Wiz::LocalTime::ToFormatStr(OutStr, InFmt, TempTime);

                return ::Wiz::Bool::True;
            }

            return ::Wiz::Bool::False;
        }
    } /// end of namespace Time
} /// end of namespace Wiz

#endif /*__WIZ_BASE_TYPE_TIME_HPP__SHANHAOBO_19800429__*/

